package entity

import (
	"fmt"

	"gorm.io/gorm"
	"shqsoft.cn/pas3ui/base"
)

//IndiKhdjYg 客户经理定级员工导入
type IndiKhdjYg struct {
	ID   int    `gorm:"AUTO_INCREMENT;primary_key;column:ID"`
	EMID int    `gorm:"column:EMID"`
	EMNO string `gorm:"column:EMNO"`
	EMNM string `gorm:"column:EMNM"`
	DRJG string `gorm:"column:DRJG"`
}

func (t *IndiKhdjYg) BeforeCreate(tx *gorm.DB) (err error) {
	err = tx.Raw(`SELECT "ID" FROM "T_SysUser" WHERE "SysUserID"=?`, t.EMNO).Row().Scan(&t.EMID)
	if err != nil {
		err = fmt.Errorf("员工%s在系统中不存在！", t.EMNM)
		return
	}
	return
}

//TableName  客户经理定级员工导入表名
func (IndiKhdjYg) TableName() string {
	return "T_INDI_KHDJ_YG"
}

//IndiKhdjYgEF 返回结构体
func IndiKhdjYgEF() base.EntityFunc {
	return func() interface{} {
		entity := IndiKhdjYg{}
		return &entity
	}
}

//IndiKhdjYgESF 返回结构体数组
func IndiKhdjYgESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []IndiKhdjYg
		return &entities
	}
}

func init() {
	base.DaoPoolObj.Put("IndiKhdjYg", base.NewDefaultDao(IndiKhdjYgEF(), IndiKhdjYgESF(), nil, "my"))
}
